<template>
  <scroll-view scroll-y class="death-simulator">
    <!-- 返回按钮 -->
    <view class="back-button" @tap="goBack">
      <text class="back-icon">←</text>
      <text class="back-text">返回</text>
    </view>
    
    <!-- 知乎问题链接标题 - 移到最顶部 -->
    <view class="zhihu-link-section">
      <text class="zhihu-link">
        知乎问题："每毫秒给你1个亿，代价是你每秒被动触发一次1亿分之一的死亡率，你愿意吗？"
      </text>
    </view>
    
    <view class="container">
      <text class="title">死亡概率模拟器</text>
      
      <!-- 用户名输入区 -->
      <view class="username-section">
        <text class="username-label">请输入你的名字：</text>
        <input 
          v-model="userName" 
          type="text" 
          class="username-input"
          placeholder="例如：张三"
          maxlength="6"
        />
        <text class="username-hint">名字将用于记录和排行榜统计（留空则显示为"匿名用户"）</text>
      </view>
      
      <!-- 概率选择器 -->
      <view class="probability-section">
        <text class="probability-label">选择每秒死亡概率：</text>
        <view class="probability-options">
          <view 
            v-for="option in probabilityOptions" 
            :key="option.value"
            @tap="selectProbability(option)"
            :class="['probability-btn', { active: selectedProbability.value === option.value }]"
          >
            <text>{{ option.label }}</text>
          </view>
        </view>
        <text class="description">
          当前概率：<text class="strong">{{ selectedProbability.label }}</text>，模拟你能存活多久
        </text>
        <text class="expected-time">
          理论期望存活时间：<text class="strong">{{ expectedLifetime }}</text>
        </text>
      </view>
      
      <!-- 单次模拟 -->
      <view class="simulation-section">
        <view @tap="runSingleSimulation" :class="['sim-button', { disabled: isRunning }]">
          <text>{{ buttonText }}</text>
        </view>
        
        <!-- 运行状态显示 -->
        <view v-if="isRunning" class="running-status">
          <view class="progress-indicator">
            <view class="spinner"></view>
            <text>正在模拟中，当前已存活：<text class="current-time">{{ currentTime }}</text> 年</text>
          </view>
        </view>
        
        <view v-if="singleResult" class="result-box single-result">
          <text class="result-title">模拟结果</text>
          <text class="result-text">在 <text class="probability-text">{{ selectedProbability.label }}</text> 的死亡概率下</text>
          <text class="result-text">你存活了 <text class="highlight">{{ singleResult }}</text> 年</text>
          <text class="equivalent-text">相当于 {{ equivalentDays }} 天</text>
          
          <view class="money-result">
            <text class="money-title">💰 获得金额</text>
            <text class="money-amount">{{ earnedMoney }}</text>
            <text class="money-description">每毫秒1亿 × 存活{{ (parseFloat(singleResult) * 31536000).toFixed(0) }}秒</text>
          </view>
          
          <!-- 分享按钮 -->
          <view class="share-section">
            <button class="share-btn" open-type="share" @tap="prepareShare">
              🎉 一键分享结果
            </button>
          </view>
        </view>
      </view>
      
      <!-- 排行榜区域 -->
      <view class="ranking-section">
        <text class="ranking-title">🏆 排行榜 - {{ selectedProbability.label }}</text>
        <text class="ranking-subtitle">当前概率下存活时间最长的前10名</text>
        
        <view v-if="rankings.length === 0" class="ranking-empty">
          <text>暂无排行数据，快来创造第一个记录吧！</text>
        </view>
        
        <view v-else class="ranking-table-wrapper">
          <view class="ranking-table">
            <view class="ranking-header">
              <text class="rank-col">排名</text>
              <text class="name-col">用户名</text>
              <text class="survival-col">存活时间</text>
              <text class="money-col">获得金额</text>
              <text class="date-col">记录时间</text>
            </view>
            <view 
              v-for="(record, index) in rankings" 
              :key="record.id"
              :class="['ranking-row', { 'top-three': index < 3 }]"
            >
              <view class="rank-col">
                <text :class="['rank-badge', getRankClass(index)]">
                  {{ index === 0 ? '🥇' : index === 1 ? '🥈' : index === 2 ? '🥉' : index + 1 }}
                </text>
              </view>
              <text class="name-col">{{ record.userName || '匿名用户' }}</text>
              <view class="survival-col">
                <text class="survival-years">{{ record.survivalYears.toFixed(2) }}</text>
                <text> 年</text>
                <text class="days-text">({{ record.survivalDays }} 天)</text>
              </view>
              <text class="money-col">{{ record.earnedMoney }}</text>
              <text class="date-col">{{ formatDate(record.timestamp) }}</text>
            </view>
          </view>
        </view>
      </view>
    </view>

    <!-- 底部公众号 -->
    <view class="author-footer">
      <text class="official-account-link" @tap="openOfficialAccount">
        关注公众号
      </text>
    </view>
  </scroll-view>
</template>

<script setup lang="ts">
import { ref, computed, watch, onMounted, inject } from 'vue';
import { insertRanking, getRankingByProbability, type RankingRecord } from '@/services/rankingService';

const emit = defineEmits(['go-back']);

// 注入父组件的分享数据更新函数
const updateShareData = inject<(title: string, path: string) => void>('updateShareData');

// 每年秒数（近似）
const SECONDS_PER_YEAR = 60 * 60 * 24 * 365;

// 用户名（默认空字符串，提交时如果为空则使用"匿名用户"）
const userName = ref('');

// 概率选项（从小概率到大概率排列）
const probabilityOptions = [
  { label: '十亿分之一', value: 1 / 1000000000, description: '1/1,000,000,000', key: '1e-9' },
  { label: '一亿分之一', value: 1 / 100000000, description: '1/100,000,000', key: '1e-8' },
  { label: '千万分之一', value: 1 / 10000000, description: '1/10,000,000', key: '1e-7' },
  { label: '百万分之一', value: 1 / 1000000, description: '1/1,000,000', key: '1e-6' }
];

// 当前选中的概率（默认选择十亿分之一）
const selectedProbability = ref({ label: '十亿分之一', value: 1 / 1000000000, description: '1/1,000,000,000', key: '1e-9' });

// 状态管理
const isRunning = ref(false);
const currentTime = ref('0.00');

// 结果存储
const singleResult = ref<string | null>(null);

// 排行榜数据
const rankings = ref<RankingRecord[]>([]);

// 计算属性
const buttonText = computed(() => {
  if (isRunning.value) {
    return '模拟中...';
  }
  return '开始模拟';
});

const equivalentDays = computed(() => {
  if (!singleResult.value) return '0';
  return (parseFloat(singleResult.value) * 365).toFixed(0);
});

// 计算获得的金额
const earnedMoney = computed(() => {
  if (!singleResult.value) return '0';
  
  const years = parseFloat(singleResult.value);
  const seconds = years * SECONDS_PER_YEAR;
  const milliseconds = seconds * 1000;
  const totalMoney = milliseconds * 100000000; // 每毫秒1亿
  
  return formatMoney(totalMoney);
});

// 获得的金额（数值）
const earnedMoneyValue = computed(() => {
  if (!singleResult.value) return 0;
  
  const years = parseFloat(singleResult.value);
  const seconds = years * SECONDS_PER_YEAR;
  const milliseconds = seconds * 1000;
  return milliseconds * 100000000; // 每毫秒1亿
});

const expectedLifetime = computed(() => {
  if (!selectedProbability.value) return '计算中...';
  
  const expectedSeconds = 1 / selectedProbability.value.value;
  
  // 根据时间长度选择最合适的单位显示
  if (expectedSeconds < 60) {
    return `${expectedSeconds.toFixed(1)} 秒`;
  } else if (expectedSeconds < 3600) {
    const minutes = (expectedSeconds / 60).toFixed(1);
    return `${minutes} 分钟`;
  } else if (expectedSeconds < 86400) {
    const hours = (expectedSeconds / 3600).toFixed(1);
    return `${hours} 小时`;
  } else if (expectedSeconds < 31536000) {
    const days = (expectedSeconds / 86400).toFixed(1);
    return `${days} 天`;
  } else {
    const years = (expectedSeconds / SECONDS_PER_YEAR);
    if (years < 1000) {
      return `${years.toFixed(1)} 年`;
    } else if (years < 1000000) {
      const thousands = (years / 1000).toFixed(1);
      return `${thousands} 千年`;
    } else {
      const millions = (years / 1000000).toFixed(1);
      return `${millions} 百万年`;
    }
  }
});

onMounted(() => {
  // 组件加载时获取当前概率的排行榜
  loadRankings();
});

watch(() => selectedProbability.value.key, () => {
  // 监听概率变化，重新加载排行榜
  loadRankings();
});

// 方法
function goBack() {
  emit('go-back');
}

function openOfficialAccount() {
  // 跳转到公众号主页，静默处理错误
  uni.openOfficialAccountProfile({
    username: 'gh_ab75ef78354d',
    success: () => {
      console.log('成功打开公众号主页');
    },
    fail: (err: any) => {
      console.error('打开公众号失败:', err);
      // 不显示任何提示
    }
  });
}

// 加载排行榜数据
async function loadRankings() {
  console.log('===== 开始刷新排行榜 =====');
  console.log('当前概率:', selectedProbability.value.key);
  try {
    const result = await getRankingByProbability(selectedProbability.value.key, 10);
    console.log('排行榜API返回结果:', result);
    if (result.success) {
      rankings.value = result.data.records;
      console.log('✅ 排行榜已更新，记录数:', rankings.value.length);
    } else {
      console.error('❌ 排行榜刷新失败:', result.message);
    }
  } catch (error) {
    console.error('❌ 加载排行榜异常:', error);
  }
}

// 保存记录到排行榜
async function saveToRanking() {
  console.log('===== saveToRanking 方法被调用 =====');
  
  if (!singleResult.value) {
    console.warn('没有模拟结果，跳过保存');
    return;
  }
  
  const recordData = {
    userName: userName.value.trim() || '匿名用户',
    probability: selectedProbability.value.key,
    probabilityLabel: selectedProbability.value.label,
    survivalYears: parseFloat(singleResult.value),
    survivalDays: parseInt(equivalentDays.value),
    earnedMoney: earnedMoney.value,
    earnedMoneyValue: earnedMoneyValue.value.toString()  // 转为字符串，避免超出Long范围
  };
  
  console.log('准备保存的数据:', recordData);
  
  try {
    console.log('开始调用 insertRanking...');
    const result = await insertRanking(recordData);
    console.log('insertRanking 返回结果:', result);
    
    if (result.success) {
      console.log('✅ 记录已成功保存到排行榜');
      // 重新加载排行榜
      await loadRankings();
    } else {
      console.error('❌ 保存失败:', result.message);
      // 静默处理失败，不弹窗提示
    }
  } catch (error) {
    console.error('❌ 保存记录异常:', error);
    // 静默处理异常，不弹窗提示
  }
}

// 格式化日期显示
function formatDate(isoString: string): string {
  const date = new Date(isoString);
  const year = date.getFullYear();
  const month = String(date.getMonth() + 1).padStart(2, '0');
  const day = String(date.getDate()).padStart(2, '0');
  const hours = String(date.getHours()).padStart(2, '0');
  const minutes = String(date.getMinutes()).padStart(2, '0');
  return `${year}-${month}-${day} ${hours}:${minutes}`;
}

// 获取排名样式类
function getRankClass(index: number): string {
  if (index === 0) return 'rank-first';
  if (index === 1) return 'rank-second';
  if (index === 2) return 'rank-third';
  return '';
}

// 选择概率
function selectProbability(option: any) {
  selectedProbability.value = option;
  singleResult.value = null; // 清除之前的结果
}

// 单次模拟 - 优化版本
async function runSingleSimulation() {
  if (isRunning.value) return;
  
  isRunning.value = true;
  singleResult.value = null;
  currentTime.value = '0.00';
  
  // 使用几何分布直接计算死亡时间
  const finalSecondsLived = calculateDeathTime();
  const finalYearsLived = finalSecondsLived / SECONDS_PER_YEAR;
  
  // 根据概率调整动画参数
  const animationParams = getAnimationParams();
  
  // 动画函数 - 快速递增到最终结果
  await animateToResult(finalSecondsLived, finalYearsLived, animationParams);
  
  // 设置最终结果
  singleResult.value = finalYearsLived.toFixed(2);
  isRunning.value = false;
  
  // 保存记录到排行榜
  await saveToRanking();
}

// 使用几何分布计算死亡时间
function calculateDeathTime(): number {
  const p = selectedProbability.value.value;
  
  // 使用正确的几何分布逆变换采样公式
  // X = ceil(log(U) / log(1-p)) 其中 U ~ Uniform(0,1)
  const u = Math.random();
  
  // 确保u不为0，避免log(0)的问题
  const u_safe = Math.max(u, 1e-10);
  
  // 几何分布的逆变换采样（正确公式）
  const deathTime = Math.ceil(Math.log(u_safe) / Math.log(1 - p));
  
  return Math.max(1, deathTime);
}

// 根据概率获取动画参数
function getAnimationParams() {
  const p = selectedProbability.value.value;
  const expectedSeconds = 1 / p;
  
  // 根据期望存活时间调整动画参数
  if (expectedSeconds < 100000) {
    return {
      interval: 60,
      totalSteps: 30
    };
  } else if (expectedSeconds < 50000000) {
    return {
      interval: 50,
      totalSteps: 35
    };
  } else if (expectedSeconds < 500000000) {
    return {
      interval: 45,
      totalSteps: 40
    };
  } else {
    return {
      interval: 35,
      totalSteps: 45
    };
  }
}

// 动画到结果
function animateToResult(finalSecondsLived: number, finalYearsLived: number, animationParams: any): Promise<void> {
  return new Promise((resolve) => {
    let step = 0;
    const totalSteps = animationParams.totalSteps;
    
    const animate = () => {
      step++;
      
      // 使用easing function创建平滑动画
      const progress = step / totalSteps;
      const easedProgress = 1 - Math.pow(1 - progress, 3); // 缓出动画
      
      const currentSeconds = finalSecondsLived * easedProgress;
      const currentYears = currentSeconds / SECONDS_PER_YEAR;
      currentTime.value = currentYears.toFixed(2);
      
      if (step >= totalSteps) {
        // 确保最终值准确
        currentTime.value = finalYearsLived.toFixed(2);
        resolve();
        return;
      }
      
      // 递归调用，创建平滑动画
      setTimeout(animate, animationParams.interval);
    };
    
    animate();
  });
}

// 格式化金额显示
function formatMoney(amount: number): string {
  if (amount === 0) return '0元';
  
  // 转换为中文单位
  const units = [
    { name: '元', value: 1 },
    { name: '万元', value: 10000 },
    { name: '亿元', value: 100000000 },
    { name: '万亿元', value: 1000000000000 },
    { name: '千万亿元', value: 10000000000000000 },
    { name: '亿亿元', value: 100000000000000000 }
  ];
  
  // 找到合适的单位
  for (let i = units.length - 1; i >= 0; i--) {
    const unit = units[i];
    if (unit && amount >= unit.value) {
      const value = amount / unit.value;
      if (value >= 1000) {
        return `${(value / 1000).toFixed(1)}千${unit.name}`;
      } else {
        return `${value.toFixed(1)}${unit.name}`;
      }
    }
  }
  
  return `${amount.toFixed(0)}元`;
}

// 准备分享数据
function prepareShare() {
  if (!singleResult.value) return;
  
  const years = parseFloat(singleResult.value);
  const days = equivalentDays.value;
  const money = earnedMoney.value;
  
  // 生成吸引人的分享文案
  let shareTitle = '';
  
  if (years >= 1000) {
    shareTitle = `🎉 太惊人了！存活了 ${singleResult.value} 年，获得了 ${money}！`;
  } else if (years >= 100) {
    shareTitle = `💪 厉害！存活了 ${singleResult.value} 年，赚取了 ${money}！`;
  } else if (years >= 10) {
    shareTitle = `🎯 存活了 ${singleResult.value} 年，获得了 ${money}！`;
  } else {
    shareTitle = `😱 存活了 ${days} 天，获得了 ${money}！`;
  }
  
  // 更新父组件的分享数据
  if (updateShareData) {
    updateShareData(shareTitle, '/pages/game');
  }
}
</script>

<style scoped>
.death-simulator {
  min-height: 100vh;
  width: 100%;
  max-width: 100vw;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 40rpx 20rpx;
  position: relative;
  overflow-x: hidden;
  box-sizing: border-box;
}

/* 返回按钮样式 */
.back-button {
  position: fixed;
  top: 20rpx;
  left: 20rpx;
  display: flex;
  align-items: center;
  gap: 10rpx;
  padding: 16rpx 28rpx;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 100rpx;
  box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.15);
  z-index: 1000;
  transition: all 0.3s ease;
}

.back-button:active {
  transform: scale(0.95);
  box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.2);
}

.back-icon {
  font-size: 36rpx;
  color: #45B05D;
  font-weight: bold;
  line-height: 1;
}

.back-text {
  font-size: 28rpx;
  color: #2c3e50;
  font-weight: 600;
}

.container {
  max-width: 100%;
  width: 100%;
  background: rgba(255, 255, 255, 0.95);
  padding: 40rpx 30rpx;
  border-radius: 30rpx;
  box-shadow: 0 20rpx 60rpx rgba(0, 0, 0, 0.2);
  box-sizing: border-box;
}

/* 知乎链接标题样式 - 置于最顶部 */
.zhihu-link-section {
  max-width: 100%;
  width: 100%;
  text-align: center;
  margin-bottom: 40rpx;
  margin-top: 40rpx;
  padding: 24rpx 20rpx;
  background: linear-gradient(135deg, #ff6b6b, #ee5a24);
  border-radius: 24rpx;
  box-shadow: 0 8rpx 30rpx rgba(238, 90, 36, 0.3);
  box-sizing: border-box;
}

.zhihu-link {
  color: white;
  font-size: 28rpx;
  font-weight: 600;
  line-height: 1.5;
  text-shadow: 1rpx 1rpx 2rpx rgba(0, 0, 0, 0.2);
  display: block;
}

.title {
  font-size: 50rpx;
  color: #2c3e50;
  text-align: center;
  margin-bottom: 60rpx;
  font-weight: bold;
  display: block;
}

/* 用户名输入区样式 */
.username-section {
  margin-bottom: 60rpx;
  padding: 40rpx;
  background: linear-gradient(135deg, #f0f4f8, #e3eaf2);
  border-radius: 24rpx;
  border: 2rpx solid rgba(69, 176, 93, 0.3);
}

.username-label {
  display: block;
  font-size: 30rpx;
  font-weight: 600;
  color: #2c3e50;
  margin-bottom: 20rpx;
}

.username-input {
  width: 100%;
  height: 88rpx;
  padding: 0 30rpx;
  font-size: 28rpx;
  line-height: 88rpx;
  border: 2rpx solid #d1d9e6;
  border-radius: 16rpx;
  background: #ffffff;
  color: #2c3e50;
  box-sizing: border-box;
  appearance: none;
  -webkit-appearance: none;
  outline: none;
  transition: all 0.3s ease;
}

.username-input:focus {
  border-color: #45B05D;
  background: #ffffff;
  box-shadow: 0 0 0 4rpx rgba(69, 176, 93, 0.1);
}

.username-input::placeholder {
  color: #95a5a6;
}

.username-hint {
  display: block;
  margin: 16rpx 0 0 0;
  font-size: 24rpx;
  color: #7f8c8d;
  font-style: italic;
  position: relative;
  z-index: 1;
}

/* 概率选择器样式 */
.probability-section {
  margin-bottom: 60rpx;
}

.probability-label {
  display: block;
  font-size: 32rpx;
  font-weight: 600;
  color: #2c3e50;
  margin-bottom: 30rpx;
  text-align: center;
}

.probability-options {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20rpx;
  margin-bottom: 30rpx;
}

.probability-btn {
  padding: 20rpx 30rpx;
  font-size: 26rpx;
  font-weight: 500;
  color: #7f8c8d;
  background: rgba(127, 140, 141, 0.1);
  border: 2rpx solid rgba(127, 140, 141, 0.3);
  border-radius: 16rpx;
  text-align: center;
}

.probability-btn.active {
  background: linear-gradient(45deg, #3498db, #2980b9);
  color: white;
  border-color: #2980b9;
  box-shadow: 0 6rpx 20rpx rgba(52, 152, 219, 0.3);
}

.description {
  display: block;
  text-align: center;
  color: #7f8c8d;
  font-size: 30rpx;
  line-height: 1.6;
  margin-bottom: 16rpx;
}

.strong {
  font-weight: 600;
  color: #2c3e50;
}

.expected-time {
  display: block;
  text-align: center;
  color: #5a5a5a;
  font-size: 26rpx;
  font-style: italic;
  margin-top: 0;
  padding: 16rpx 30rpx;
  background: rgba(52, 152, 219, 0.1);
  border-radius: 16rpx;
  border: 1rpx solid rgba(52, 152, 219, 0.2);
}

/* 模拟按钮 */
.simulation-section {
  margin-bottom: 60rpx;
}

.sim-button {
  width: 100%;
  padding: 36rpx 50rpx;
  font-size: 32rpx;
  font-weight: bold;
  color: white;
  border-radius: 20rpx;
  text-align: center;
  background: linear-gradient(45deg, #4CAF50, #45a049);
  box-shadow: 0 8rpx 30rpx rgba(76, 175, 80, 0.3);
}

.sim-button.disabled {
  background: linear-gradient(45deg, #bdc3c7, #95a5a6);
  box-shadow: 0 4rpx 16rpx rgba(189, 195, 199, 0.3);
}

/* 运行状态显示 */
.running-status {
  margin-top: 40rpx;
}

.progress-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 40rpx;
  background: linear-gradient(135deg, #f8f9fa, #e9ecef);
  border-radius: 20rpx;
  border-left: 8rpx solid #3498db;
}

.spinner {
  width: 80rpx;
  height: 80rpx;
  border: 8rpx solid #f3f3f3;
  border-top: 8rpx solid #3498db;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 30rpx;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.current-time {
  color: #3498db;
  font-size: 1.1em;
  font-weight: bold;
}

/* 结果显示 */
.result-box {
  margin-top: 50rpx;
  padding: 50rpx;
  border-radius: 24rpx;
  background: linear-gradient(135deg, #e8f5e8, #c8e6c9);
  border-left: 10rpx solid #4CAF50;
}

.result-title {
  display: block;
  margin: 0 0 30rpx 0;
  color: #2c3e50;
  font-size: 36rpx;
  font-weight: 600;
}

.result-text {
  display: block;
  margin-bottom: 20rpx;
  font-size: 28rpx;
  color: #2c3e50;
}

.probability-text {
  color: #3498db;
  font-weight: 600;
}

.highlight {
  color: #e74c3c;
  font-size: 1.4em;
  font-weight: bold;
}

.equivalent-text {
  display: block;
  color: #7f8c8d;
  font-size: 26rpx;
  margin-top: 16rpx;
  font-style: italic;
}

/* 金额结果样式 */
.money-result {
  margin-top: 40rpx;
  padding: 40rpx;
  background: linear-gradient(135deg, #ffecd2, #fcb69f);
  border-radius: 24rpx;
  border: 2rpx solid #f39c12;
  box-shadow: 0 8rpx 30rpx rgba(243, 156, 18, 0.3);
}

.money-title {
  display: block;
  margin: 0 0 24rpx 0;
  color: #d35400;
  font-size: 32rpx;
  font-weight: bold;
  text-align: center;
}

.money-amount {
  display: block;
  font-size: 44rpx;
  font-weight: bold;
  color: #c0392b;
  text-align: center;
  margin: 20rpx 0;
  text-shadow: 1rpx 1rpx 2rpx rgba(0, 0, 0, 0.1);
}

.money-description {
  display: block;
  font-size: 24rpx;
  color: #8e44ad;
  text-align: center;
  font-style: italic;
  margin-top: 16rpx;
}

/* 分享功能样式 */
.share-section {
  margin-top: 50rpx;
  text-align: center;
}

.share-btn {
  width: 100%;
  padding: 30rpx 50rpx;
  font-size: 30rpx;
  font-weight: 600;
  color: white;
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  border-radius: 100rpx;
  text-align: center;
  box-shadow: 0 8rpx 30rpx rgba(245, 87, 108, 0.3);
  border: none;
  line-height: normal;
}

.share-btn::after {
  border: none;
}

/* 排行榜样式 */
.ranking-section {
  margin-top: 80rpx;
  padding: 22rpx;
  background: linear-gradient(135deg, #f8f9fa, #e9ecef);
  border-radius: 30rpx;
  border: 2rpx solid #dee2e6;
}

.ranking-title {
  display: block;
  font-size: 44rpx;
  color: #2c3e50;
  text-align: center;
  margin-bottom: 20rpx;
  font-weight: bold;
}

.ranking-subtitle {
  display: block;
  text-align: center;
  color: #7f8c8d;
  font-size: 26rpx;
  margin-bottom: 50rpx;
}

.ranking-empty {
  text-align: center;
  padding: 80rpx 40rpx;
  color: #95a5a6;
  font-size: 30rpx;
}

.ranking-table-wrapper {
  border-radius: 20rpx;
  box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

.ranking-table {
  width: 100%;
  background: white;
  font-size: 22rpx;
}

.ranking-header {
  display: flex;
  background: linear-gradient(135deg, #45B05D, #3D9E51);
  color: white !important;
  padding: 20rpx 12rpx;
  font-weight: 600;
  font-size: 22rpx;
  align-items: center;
}

.ranking-header .rank-col,
.ranking-header .name-col,
.ranking-header .survival-col,
.ranking-header .money-col,
.ranking-header .date-col {
  color: white !important;
}

.ranking-row {
  display: flex;
  padding: 16rpx 12rpx;
  border-bottom: 1rpx solid #f0f0f0;
  align-items: center;
}

.ranking-row.top-three {
  background: linear-gradient(135deg, rgba(255, 215, 0, 0.05), rgba(255, 223, 0, 0.1));
}

.rank-col {
  width: 16%;
  text-align: center;
  flex-shrink: 0;
}

.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56rpx;
  height: 56rpx;
  border-radius: 50%;
  font-weight: bold;
  font-size: 22rpx;
}

.rank-badge.rank-first {
  background: linear-gradient(135deg, #ffd700, #ffed4e);
  color: #d35400;
  box-shadow: 0 4rpx 16rpx rgba(255, 215, 0, 0.4);
}

.rank-badge.rank-second {
  background: linear-gradient(135deg, #c0c0c0, #e8e8e8);
  color: #555;
  box-shadow: 0 4rpx 16rpx rgba(192, 192, 192, 0.4);
}

.rank-badge.rank-third {
  background: linear-gradient(135deg, #cd7f32, #e6a567);
  color: white;
  box-shadow: 0 4rpx 16rpx rgba(205, 127, 50, 0.4);
}

.name-col {
  width: 15%;
  font-weight: 600;
  color: #2c3e50;
  flex-shrink: 0;
  white-space: normal;
  word-break: keep-all;
  word-wrap: break-word;
  font-size: 22rpx;
  line-height: 1.4;
  max-width: 15%;
}

.survival-col {
  width: 27%;
  flex-shrink: 0;
}

.survival-years {
  color: #e74c3c;
  font-size: 22rpx;
  font-weight: 600;
}

.days-text {
  display: block;
  font-size: 18rpx;
  color: #95a5a6;
  margin-top: 2rpx;
}

.money-col {
  width: 26%;
  color: #2c3e50;
  font-weight: 600;
  flex-shrink: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 20rpx;
}

.date-col {
  width: 16%;
  color: #2c3e50;
  font-size: 18rpx;
  flex-shrink: 0;
  text-align: right;
}

/* 底部作者信息样式 */
.author-footer {
  width: 100%;
  text-align: center;
  padding: 40rpx;
  margin-top: 60rpx;
}

.official-account-link {
  font-size: 24rpx;
  color: rgba(255, 255, 255, 0.7);
  text-decoration: underline;
  display: inline-block;
}
</style>

